package com.wn.web;

import com.wn.pojo.Product;
import com.wn.response.ResponseCode;
import com.wn.response.ServerResponse;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@CrossOrigin
@RestController
public class ProductController {
@PostMapping("getAllProduct")
    public ServerResponse getAllProduct(@RequestHeader("token") String token){
    Product product1=new Product(1,"苹果",9999.99);
    Product product2=new Product(2,"华为",8888.99);
    Product product3=new Product(3,"小米",7777.99);
    List list=new ArrayList();
    list.add(product1);
    list.add(product2);
    list.add(product3);
    if(token==null||token.equals("")||token.equals("undefined")){
      return   new ServerResponse(ResponseCode.ERROR,"请先登录");
    }else {
        return new ServerResponse(ResponseCode.SUCCESS, list, "商品列表");
    }
}
//商品详情
    @GetMapping("getProductById/{id}")
    public   ServerResponse getProductById(@PathVariable Integer id){
        Product product1=new Product(1,"苹果",9999.99);
        Product product2=new Product(2,"华为",8888.99);
        Product product3=new Product(3,"小米",7777.99);


        switch (id){
            case 1:

                return new ServerResponse(ResponseCode.SUCCESS,product1);
            case 2:
                return new ServerResponse(ResponseCode.SUCCESS,product2);
            case 3:
                return new ServerResponse(ResponseCode.SUCCESS,product3);
            default:
                return new ServerResponse(ResponseCode.ERROR,"系统维护中");
        }


    }
}
